package com.hnas.oracle.dao.impl;

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Component;

import com.hnas.core.dao.HntBaseDaoImpl;
import com.hnas.oracle.dao.HntEmployeeCardDAO;
import com.hnas.oracle.domain.HntEmployeeInfo;
import com.hnas.oracle.orm.HntEmployeeCard;

@Component("hntEmployeeCardDAO")
public class HntEmployeeCardDAOImpl extends HntBaseDaoImpl<HntEmployeeCard> implements HntEmployeeCardDAO {

	public HntEmployeeCardDAOImpl() {
		super(HntEmployeeCard.class);
	}


	@Override
	public List<HntEmployeeCard> getCardList(String employeeId) {
		String hql = "from HntEmployeeCard t where t.EMPLOYEE_ID = ?1";
		return this.findByQuery(hql, employeeId);
	}


	@Override
	public HntEmployeeInfo findEmployeeByCardNo(String cardNo) {
		String sql = "select t1.employee_id,t1.employee_name,t1.account from hnt_dev.m_base_info_employeeinfo t1 left join hnt_dev.m_base_employee_card t2 on t1.employee_id = t2.employee_id where t1.flag = 1 and t2.flag = 1 and t2.card_no = '"+cardNo+"' order by t2.card_date desc";
		Query query = this.entityManager.createNativeQuery(sql);
		List<Object[]> resultList = query.getResultList();
		if(resultList != null && resultList.size() > 0){
			Object[] objs = resultList.get(0);
			HntEmployeeInfo empInfo = new HntEmployeeInfo();
			empInfo.setEmployeeId(String.valueOf(objs[0]));
			empInfo.setEmployeeName(String.valueOf(objs[1]));
			empInfo.setAccount(String.valueOf(objs[2]));
			return empInfo;
		}
		return null;
	}


}
